package weaver.interfaces.qz.job;

import com.engine.qz.service.impl.CommissionServiceImpl;
import org.springframework.util.CollectionUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.interfaces.schedule.BaseCronJob;

import java.time.LocalDate;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Title ecology-9
 * @Company 泛微软件
 * @CreateDate 2025/8/5
 * @Description 提成计算
 * @Author AdminZm
 */
public class CountCommissionJob extends BaseCronJob {

    BaseBean baseBean = new BaseBean();

    @Override
    public void execute() {
        baseBean.writeLog("CountCommissionJob start.");
        try {
            RecordSet rs = new RecordSet();
            CommissionServiceImpl commissionServiceImpl = new CommissionServiceImpl();
            List<String> faIdList = new ArrayList<>();
            rs.execute("SELECT id FROM uf_tcfasz");
            while (rs.next()) {
                String faId = rs.getString("id");
                faIdList.add(faId);
            }
            baseBean.writeLog("CountCommissionJob faIdList is:" + faIdList);
            if (CollectionUtils.isEmpty(faIdList)) {
                return;
            }
            Map<String, Object> params = new HashMap<>();
            params.put("tcfa", String.join(",", faIdList));
            params.put("ryid", "");
            Map<String, Object> map = commissionServiceImpl.countCommission(params);
            baseBean.writeLog("CountCommissionJob result:" + map);
        } catch (Exception e) {
            baseBean.writeLog("CountCommissionJob error:" + e);
        }
        baseBean.writeLog("CountCommissionJob end.");
    }
}
